home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / smalltlk.zip / PRELUDE / BLOCK.ST < prev    next >
Text File  |  1987-06-17  |  1KB  |  60 lines

  1. "
  2.     Class Block.
  3.  
  4.     Note how whileTrue: and whileFalse: depend upon the parser
  5.     optimizing the loops into control flow, rather than message
  6.     passing.  If this were not the case, whileTrue: would have to
  7.     be implemented using recursion, as follows:
  8.  
  9.     whileTrue: aBlock
  10.         (self value) ifFalse: [^nil].
  11.         aBlock value.
  12.         ^ self whileTrue: aBlock
  13. "
  14. Class Block
  15. [
  16.     newProcess
  17.         ^ <NewProcess  self>
  18. |
  19.     newProcessWith: argumentArray
  20.         ^ <NewProcess  self argumentArray>
  21. |
  22.     fork
  23.         self newProcess resume.
  24.         ^ nil
  25. |
  26.     forkWith: argumentArray
  27.         (self newProcessWith: argumentArray) resume.
  28.         ^ nil
  29. |
  30.     whileTrue
  31.         ^ [self value ] whileTrue: []
  32. |
  33.     whileTrue: aBlock
  34.         ^ [ self value ] whileTrue: [ aBlock value ]
  35. |
  36.     whileFalse
  37.         ^ [ self value ] whileFalse: []
  38. |
  39.     whileFalse: aBlock
  40.         ^ [ self value ] whileFalse: [ aBlock value ]
  41. |
  42.      value
  43.         <BlockExecute  0>
  44. |
  45.     value: a
  46.         <BlockExecute  1>
  47. |
  48.     value: a value: b
  49.         <BlockExecute  2>
  50. |
  51.     value: a value: b value: c
  52.         <BlockExecute  3>
  53. |
  54.     value: a value: b value: c value: d
  55.         <BlockExecute  4>
  56. |
  57.     value: a value: b value: c value: d value: e
  58.         <BlockExecute  5>
  59. ]
  60.